<template>

    <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="销售订单号">
            <el-input v-model="formInline.Documentnumber" placeholder="销售订单号" clearable />
        </el-form-item>

        <el-form-item label="单据编码">
            <el-input v-model="formInline.returnNumber" placeholder="开票名称" clearable />
        </el-form-item>

        <el-form-item label="客户名称">
            <el-input v-model="formInline.clientName" placeholder="客户名称" clearable />
        </el-form-item>

        <el-form-item label="销售人员">
            <el-input v-model="formInline.salesStaff" placeholder="开票名称" clearable />
        </el-form-item>

        <el-form-item label="物料名称">
            <el-input v-model="formInline.materialName" placeholder="开票名称" clearable />
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="GetData()">搜索</el-button>
        </el-form-item>
    </el-form>
    
    <el-button type="primary" :icon="List" @click="GetData1()">查询所有</el-button>
    <el-button type="primary" :icon="List" @click="router.push('')">单据</el-button>
    <el-button type="primary" :icon="Plus" @click="router.push('/ReturnNotice/AddReturnNoticeView')" >新增</el-button>
    <el-button type="primary" :icon="Download">导入</el-button>
    <el-button type="primary" :icon="Upload">导出</el-button>

    <!-- v-show="suppliers.length == 0" v-show="suppliers.length != 0" -->
    <el-table :data="suppliers" stripe style="width: 100%" >
        <el-table-column prop="returnNoticesId" label="序号" />
        <el-table-column prop="documentnumber" label="销售订单号" />
        <el-table-column prop="returnNumber" label="单据编码">
            <template #default="scope">
                <el-link type="primary" @click="chakan(scope.row.returnNumber)">{{
                    scope.row.returnNumber }}</el-link>
            </template>
        </el-table-column>
            
        <el-table-column prop="documentstatus" label="单据状态" />
        <el-table-column prop="clientName" label="客户名称" />
        <el-table-column prop="materialName" label="物料名称" />
        <el-table-column prop="itemBianma" label="物料编码" />
        <el-table-column prop="piHao" label="批号" />
        <el-table-column prop="returnShulnum" label="退货数量" />
        <el-table-column prop="beginNumbere" label="入库数量" />
        <el-table-column prop="documentsDate" label="单据日期">
            <template #default="scope">
                {{ scope.row.documentsDate.substr(0,10) }}</template>
        </el-table-column>
    </el-table>


    <div>
        <tr>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="total, slot, prev, pager, next"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
            <td>
                <el-pagination v-model:current-page="formInline.pageIndex" v-model:page-size="formInline.pageSize"
                    :page-sizes="[10, 20, 30, 40, 50]" :background="true" layout="slot, sizes, jumper"
                    :total="formInline.totalCount" @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </td>
        </tr>
    </div>

</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRoute } from 'vue-router'
import axios from 'axios';
import { Plus, Download, Upload, List } from '@element-plus/icons-vue'
import type { TabsPaneContext } from 'element-plus'
const router = useRouter()
const route = useRoute()
const apiurls = import.meta.env.VITE_APP_API_URL_BasicInformationCommon;//5176
const bpiurls = import.meta.env.VITE_APP_API_URL_BasicInformationWrite;//5013
const cpiurls = import.meta.env.VITE_APP_API_URL_RBACCommon;//5214
const dpiurls = import.meta.env.VITE_APP_API_URL_RBACWrite;//5268
const epiurls = import.meta.env.VITE_APP_API_URL_SalesManagementCommon;//5227
const fpiurls = import.meta.env.VITE_APP_API_URL_SalesManagementWrite;//5020

onMounted(() => {
    GetData()
});

const formInline = reactive({
    Documentnumber: '',
    returnNumber: '',
    clientName: '',
    salesStaff: '',
    materialName: '',
    pageIndex: 1,
    pageSize: 10,
    totalPage: 0,
    totalCount: 0,

})

//销售订单单据列表
const suppliers: any = ref([]);
const GetData = () => {
    axios
        .get(
            epiurls+'/api/ReturnNoticeses/GetreturnNotice',
            {
                params: {
                    Documentnumber: formInline.Documentnumber,
                    returnNumber: formInline.returnNumber,
                    clientName: formInline.clientName,
                    salesStaff: formInline.salesStaff,
                    materialName: formInline.materialName,
                    pageIndex: formInline.pageIndex,
                    pageSize: formInline.pageSize,
                }
            }
        )
        .then((res) => {
            console.log(res.data.data);
            suppliers.value = res.data.data.list;
            formInline.totalPage = res.data.data.totalPage;
            formInline.totalCount = res.data.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};

const GetData1 = () => {
    axios
        .get(
            epiurls+'/api/ReturnNoticeses/GetreturnNotice',
            {
                params: {
                    documentNumber: '',
                    returnNumber: '',
                    clientName: '',
                    salesStaff: '',
                    materialName: '',
                    pageIndex: 1,
                    pageSize: 10,
                }
            }
        )
        .then((res) => {
            console.log(res.data.data);
            suppliers.value = res.data.data.list;
            formInline.totalPage = res.data.data.totalPage;
            formInline.totalCount = res.data.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};

//分页
const handleSizeChange = (val: number) => {
    formInline.pageSize = val
    GetData()
}
const handleCurrentChange = (val: number) => {
    formInline.pageIndex = val
    GetData()
}

//编辑
const chakan = (returnNumber: any) => {
    router.push({
        path: '/ReturnNotice/UpdateReturnNoticeView',
        query: {
            returnNumber: returnNumber
        }
    })
}


</script>

<style>
.demo-tabs>.el-tabs__content {
    padding: 32px;
    color: #6b778c;
    font-size: 32px;
    font-weight: 600;
}
</style>